
<title>Update, Delete Item Specialization</title>
 

<?php

/*

***************************************
*                                     *
* Copyright 2011 David Matthew Pugh   *
* Contact Info:thebravedave@gmail.com *
*                                     *
***************************************

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
    
require_once "../services/webservices.php";
require_once "index.php";
?>
<script type="text/javascript">
    function checkform()
    {
        
        
        go=true;
        if(document.getElementById("new_descriptor").value=='')
        {
            alert("Please completely fill out new descriptor textbox.");
            go = false;
            return false;
        }
       
    }
</script> 


<?php

$isc_id = $_GET['isc_id'];

  
if(isset($_GET['do_submit']))
{ 
    $isc_id = $_GET['isc_id'];     
    $getrequest_update = new itemspecialization();
    $getrequest_update->isc_id = $isc_id;
    $getresponse_update = $getrequest_update->getitemspecializationdescriptorbyiscid();
    $xml_update = new SimpleXMLElement($getresponse_update);
    foreach($xml_update->Item as $eachitem_update)
    {   
       $isd_id = $eachitem_update->id;
       $isd_id = (string)$isd_id;        
       $new_descriptor = $_GET[$isd_id];         
       $getrequest3 = new itemspecialization();
       $getrequest3->isd_id = $isd_id;
       $getrequest3->descriptor = $new_descriptor;
       $getresponse3 = $getrequest3->updateitemspecializationdescriptor();
       $xml3 = new SimpleXMLElement($getresponse3);
       $updated = $xml3->added;
       $updated = (int)$updated;          
    }       
    $getrequest = new itemspecialization();
    $getrequest->isc_id = $isc_id;     
    $getrequest->category = $_GET['category'];
    $getresponse = $getrequest->updateitemspecializationcategory();
    $xml = new SimpleXMLElement($getresponse);              
}

$getrequest = new itemspecialization();
$getrequest->isc_id = $isc_id;
$getresponse = $getrequest->getitemspecializationcategorybyiscid();
$xml = new SimpleXMLElement($getresponse);
foreach($xml->Item as $item_count)
{
    $is_id = $item_count->id;
    $gw_id = $item_count->gw_id;
    $category = $item_count->category;    
}
if(isset($_GET['update_is']))  
{   

    if(isset($_GET['add_descriptor']))
    {
        $new_descriptor = $_GET['new_descriptor'];
        $getrequest = new itemspecialization();
        $getrequest->isc_id = $isc_id;
        $getrequest->descriptor = $new_descriptor;
        $getresponse = $getrequest->additemspecializationdescriptor();
        $xml = new SimpleXMLElement($getresponse);
        $new_isd_id = $xml->isd_id;        
        $getrequest->isd_id = $new_isd_id;
        $getrequest->gw_id = $gw_id;
        $getresponse = $getrequest->createspecificitemsfromitemspecializationdescriptor();       
    }
    if(isset($_GET['delete_descriptor']))
    {
        $isd_id = $_GET['isd_id']; 
        $gw_id = $_GET['gw_id']; 
        
        //need to delete the isd from item_specialization_descriptor
        $getrequest = new itemspecialization();
        $getrequest->isd_id = $isd_id;
        
        $getresponse = $getrequest->deleteisdandrelateddata();
               
           
    }    
    if(!isset($_GET['delete_is']))
    {  
        ?>
        <br /><br /><br /><br />
        
        <form action = "./updateitem.php" method="POST">
        <input type="hidden" name="gw_id" value="<?php echo $_GET['gw_id'];?>" />
        <input type="hidden" name="Edit_Button" vaue="Edit_Button" /> 
        <input type="submit" name="submit" value="go back"><br /><br />
        </form> 
        <form action="update_delete_item_specialization.php" method="GET" id="udis">
        <h3><b>Item specialization</b></h3>
        <div class="smallcore">
        <b>Category</b><br />
        <input type="text" id="category" name="category" value="<?php echo $category?>"><br />


        <input type="hidden" id="gw_id" name="gw_id" value="<?php echo $gw_id?>">
        <br /> 
        <b>Descriptors</b><br /> 
        <?php
        $getrequest = new itemspecialization();
        $getrequest->isc_id=$isc_id;
        $getresponse = $getrequest->getitemspecializationdescriptorbyiscid();
        $xml = new SimpleXMLElement($getresponse);
       
        foreach($xml->Item as $eachitem)
        {
            $isd_id = $eachitem->id;
            $isc_id = $eachitem->isc_id;
            $descriptor = $eachitem->descriptor;
            echo '<input type="text" name="' . $isd_id . '" value="' . $descriptor . '"><br />';
            
        }


        echo '<input type="hidden" name="do_submit" value="do_submit">';
        echo '<input type="hidden" name="is_id" value="' . $is_id . '">'; 
        echo '<input type="hidden" name="isc_id" id="isc_id" value="' . $isc_id . '">';
        echo '<input type="submit" name="update_is" id="update_is" value="update changes">';
        echo '</form>';
        echo '</div>';


        $isc_id = $_GET['isc_id']; 
   
    }    
    
    $getrequest = new itemspecialization();
    $getrequest->isc_id=$isc_id;
    $getresponse = $getrequest->getitemspecializationdescriptorbyiscid();
    $xml = new SimpleXMLElement($getresponse);
    $item_cnt = $xml->Item_Count;
    $gw_id = $_GET['gw_id'];
    if(!isset($_GET['delete_is']))
    {
        $temp_numbr = 0; 
        if ($item_cnt > 1)
        {
            echo '<br /><b>Delete Descriptor</b>'; 
            echo '<div class="smallcore">';
            
            foreach($xml->Item as $eachitem)
            {
                $isd_id = $eachitem->id;
                $isc_id = $eachitem->isc_id;
                $descriptor = $eachitem->descriptor;

                echo '
                <form action="update_delete_item_specialization.php" method="GET" id="delete_one_descriptor"><b>' . $descriptor . '</b>
                    <input type="hidden" name="gw_id" value="' . $gw_id . '">
                    <input type="hidden" name="update_is" id="update_is" value="update_is"/>
                    <input type="hidden" name="isd_id" value="' . $isd_id . '">
                    <input type="hidden" id="isc_id" name="isc_id" value="' . $isc_id . '">
                    <input type="submit" name="delete_descriptor" value="delete">
                </form><br />';
                $temp_numbr++;
            }
            echo '</div>';
        }


        echo '<b>Add Descriptor</b>';
        echo '<div class="smallcore">';  
        echo '<form action="update_delete_item_specialization.php" method="GET" id="add_extra_descriptor">';
        echo '<input type="text" id="new_descriptor" name="new_descriptor">';
        echo '<input type="hidden" id="isc_id" name="isc_id" value="' . $isc_id . '">';
        echo '<input type="hidden" id="gw_id" name="gw_id" value="' . $gw_id . '">';
        echo '<input type="hidden" name="update_is" id="update_is" value="update_is"/>';
        echo '<input type="submit" id="add_descriptor" name="add_descriptor" value="add descriptor" onclick="javascript: return checkform();"> ';
        echo '</form>';
        echo '</div>'; 
    }

   
}   
   
          
if(isset($_GET['delete_is']))
{
    $getrequest = new itemspecialization();
    $getrequest->isc_id = $isc_id;
    $getrequest->gw_id = $gw_id;
    
    $getresponse = $getrequest->deleteitemspecializationandrelateddatabyiscid();
    $getresponse = $getrequest->createspecificitems();
    
    
    
}                                 
          
           
?>


  
  
  
  
  
  
  
  
  

